package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.OutInfoService;
import com.lianwei.hospital.mapper.OutInfoMapper;
import com.lianwei.hospital.module.entity.OpdInfo;
import com.lianwei.hospital.module.entity.OutInfo;
import com.lianwei.hospital.module.vo.OutVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("OutInfoService")
public class OutInfoImpl implements OutInfoService {
    @Autowired
    OutInfoMapper outInfoMapper;

    @Override
    public OutInfo selectByPrimaryKey(int id) throws Exception {
        return outInfoMapper.selectByPrimaryKey(Math.toIntExact(id));
    }

    @Override
    public boolean insert(OutInfo outInfo) throws Exception {
        return outInfoMapper.insert(outInfo)>0;
    }

    @Override
    public List<OutInfo> selectAll() throws Exception {
        return outInfoMapper.selectAll();
    }

    @Override
    public boolean deleteByPrimaryKey(int id) throws Exception {
        return outInfoMapper.deleteByPrimaryKey(Math.toIntExact(id))>0;
    }

    @Override
    public boolean updateByPrimaryKey(OutInfo outInfo) throws Exception {
        return outInfoMapper.updateByPrimaryKey(outInfo)>0;
    }

    @Override
    public PageUtil<OutInfo> findPage(OutVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=outInfoMapper.countBySelectActive(query);
        if (count>0){
            List<OutInfo> data=outInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
